<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Examples;
use App\Http\Controllers\Controller;
use App\Models\Account;
use App\Models\Deposit;
use App\Models\Exchange;
use App\Models\GroupReward;
use App\Models\Position;
use App\Models\RecommendReward;
use App\Models\TeamReward;
use App\Models\User;
use App\Models\Withdraw;
use Carbon\Carbon;
use Dcat\Admin\Http\Controllers\Dashboard;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('数据统计')
            ->description('...')
            ->body(function (Row $row) {
                $row->column(3, function (Column $column) {
                    $count = User::whereDate('created_at', today())->count();
                    $column->row(Card::make('今日新增用户', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = User::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->count();
                    $column->row(Card::make('本周新增用户', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = User::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->count();
                    $column->row(Card::make('本月新增用户', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = User::count();
                    $column->row(Card::make('总用户数量', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Deposit::whereDate('created_at', today())->sum('amount');
                    $column->row(Card::make('今日充值', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Deposit::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->sum('amount');
                    $column->row(Card::make('本周充值', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Deposit::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->sum('amount');
                    $column->row(Card::make('本月充值', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Deposit::sum('amount');
                    $column->row(Card::make('总充值', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = Exchange::whereDate('created_at', today())->sum('number');
                    $column->row(Card::make('今日兑换', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Exchange::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->sum('number');
                    $column->row(Card::make('本周兑换', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Exchange::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->sum('number');
                    $column->row(Card::make('本月兑换', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Exchange::sum('number');
                    $column->row(Card::make('总兑换', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = Withdraw::whereDate('created_at', today())->where('status', 1)->sum('number');
                    $column->row(Card::make('今日提现', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Withdraw::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->where('status', 1)
                        ->sum('number');
                    $column->row(Card::make('本周提现', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Withdraw::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->where('status', 1)
                        ->sum('number');
                    $column->row(Card::make('本月提现', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Withdraw::where('status', 1)->sum('number');
                    $column->row(Card::make('总提现', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = RecommendReward::whereDate('created_at', today())->sum('get_number');
                    $column->row(Card::make('今日直推收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = RecommendReward::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->sum('get_number');
                    $column->row(Card::make('本周直推收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = RecommendReward::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->sum('get_number');
                    $column->row(Card::make('本月直推收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = RecommendReward::sum('get_number');
                    $column->row(Card::make('总直推收益', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = GroupReward::whereDate('created_at', today())->sum('get_number');
                    $column->row(Card::make('今日团队收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = GroupReward::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->sum('get_number');
                    $column->row(Card::make('本周团队收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = GroupReward::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->sum('get_number');
                    $column->row(Card::make('本月团队收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = GroupReward::sum('get_number');
                    $column->row(Card::make('总团队收益', $count));
                });

                $row->column(3, function (Column $column) {
                    $count = TeamReward::whereDate('created_at', today())->sum('get_number');
                    $column->row(Card::make('今日社区收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = TeamReward::where('created_at', '>', Carbon::now()->startOfWeek())
                        ->where('created_at', '<', Carbon::now()->endOfWeek())
                        ->sum('get_number');
                    $column->row(Card::make('本周社区收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = TeamReward::where('created_at', '>', Carbon::now()->startOfMonth())
                        ->where('created_at', '<', Carbon::now()->endOfMonth())
                        ->sum('get_number');
                    $column->row(Card::make('本月社区收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = TeamReward::sum('get_number');
                    $column->row(Card::make('总社区收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Position::whereDate('updated_at', today())->sum('profit');
                    $column->row(Card::make('今日机器人收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Position::where('updated_at', '>', Carbon::now()->startOfWeek())
                        ->where('updated_at', '<', Carbon::now()->endOfWeek())
                        ->sum('profit');
                    $column->row(Card::make('本周机器人收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Position::where('updated_at', '>', Carbon::now()->startOfMonth())
                        ->where('updated_at', '<', Carbon::now()->endOfMonth())
                        ->sum('profit');
                    $column->row(Card::make('本月机器人收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Position::sum('profit');
                    $column->row(Card::make('总机器人收益', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = User::where('is_active', 1)->count();
                    $column->row(Card::make('平台激活用户数', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Account::where('coin', 'ck')->sum('free');
                    $column->row(Card::make('用户CK余额总数', $count));
                });
                $row->column(3, function (Column $column) {
                    $count = Account::where('coin', 'usdt')->sum('free');
                    $column->row(Card::make('用户USDT余额总数', $count));
                });
            });
    }
}
